﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using DispatchAssist.BusinessLogical.Model;
using DispatchAssist.BusinessLogical.BLL;
using System.Web.UI.WebControls;
using System.Data;
using System.Web.Services.Protocols;

namespace DispatchAssist.WebService
{
    /// <summary>
    /// Summary description for RuleManagerService
    /// </summary>
    [WebService(Namespace = "http://DispatchAssist.ceair.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    public class RuleManagerService : System.Web.Services.WebService
    {

        #region Members.

        public DASoapHeader headerContext = new DASoapHeader();

        #endregion

        [WebMethod(Description = "获取所有预警规则信息列表")]
        [SoapHeader("headerContext", Direction = SoapHeaderDirection.In)]
        [Validation(EnableLog = true)]
        public List<AlertRule> GetAllAlertRuleRecords()
        {
            return AlertRuleManager.Instance.GetAllAlertRuleRecords();
        }

        [WebMethod(Description = "创建预警规则信息")]
        [SoapHeader("headerContext", Direction = SoapHeaderDirection.In)]
        [Validation(EnableLog = true)]
        public bool CreateAlertRule(AlertRule alertRule)
        {
            return AlertRuleManager.Instance.CreateAlertRule(alertRule);
        }

        [WebMethod(Description = "更新预警规则信息")]
        [SoapHeader("headerContext", Direction = SoapHeaderDirection.In)]
        [Validation(EnableLog = true)]
        public bool UpdateAlertRule(AlertRule alertRule)
        {
            return AlertRuleManager.Instance.UpdateAlertRule(alertRule);
        }

        [WebMethod(Description = "删除预警规则信息")]
        [SoapHeader("headerContext", Direction = SoapHeaderDirection.In)]
        [Validation(EnableLog = true)]
        public bool DeleteAlertRule(Guid alertRuleID)
        {
            return AlertRuleManager.Instance.DeleteAlertRule(alertRuleID);
        }

        [WebMethod(Description = "获取所有预警方式信息列表")]
        [SoapHeader("headerContext", Direction = SoapHeaderDirection.In)]
        [Validation(EnableLog = false)]
        public List<AlertActionDefine> GetAllAlertActionDefineRecords()
        {
            return AlertRuleManager.Instance.GetAllAlertActionDefineRecords();
        }


        [WebMethod(Description = "获取所有消息模板信息列表")]
        [SoapHeader("headerContext", Direction = SoapHeaderDirection.In)]
        [Validation(EnableLog = true)]
        public List<MsgTemplate> GetAllMsgTemplateRecords()
        {
            return MsgTemplateManager.Instance.GetAllMsgTemplateRecords();
        }

        [WebMethod(Description = "创建消息模板信息")]
        [SoapHeader("headerContext", Direction = SoapHeaderDirection.In)]
        [Validation(EnableLog = true)]
        public bool CreateMsgTemplate(MsgTemplate MsgTemplate)
        {
            return MsgTemplateManager.Instance.CreateMsgTemplate(MsgTemplate);
        }

        [WebMethod(Description = "更新消息模板信息")]
        [SoapHeader("headerContext", Direction = SoapHeaderDirection.In)]
        [Validation(EnableLog = true)]
        public bool UpdateMsgTemplate(MsgTemplate MsgTemplate)
        {
            return MsgTemplateManager.Instance.UpdateMsgTemplate(MsgTemplate);
        }

        [WebMethod(Description = "删除消息模板信息")]
        [SoapHeader("headerContext", Direction = SoapHeaderDirection.In)]
        [Validation(EnableLog = true)]
        public bool DeleteMsgTemplate(Guid MsgTemplateID)
        {
            return MsgTemplateManager.Instance.DeleteMsgTemplate(MsgTemplateID);
        }

        [WebMethod(CacheDuration = 1200, Description = "获取所有配置模板信息")]
        public DataSet GetConfigTempInfo(string type)
        {
            return MsgTemplateManager.Instance.GetConfigTempInfo(type);
        }

        [WebMethod(Description = "获取所有预警时间设置信息列表")]
        [SoapHeader("headerContext", Direction = SoapHeaderDirection.In)]
        [Validation(EnableLog = true)]
        public List<EarlyWarning> GetAllEarlyWarningRecords()
        {
            return EarlyWarningManager.Instance.GetAllEarlyWarningRecords();
        }

        [WebMethod(Description = "创建预警时间设置信息")]
        [SoapHeader("headerContext", Direction = SoapHeaderDirection.In)]
        [Validation(EnableLog = true)]
        public bool CreateEarlyWarning(EarlyWarning earlyWarning)
        {
            return EarlyWarningManager.Instance.CreateEarlyWarning(earlyWarning);
        }

        [WebMethod(Description = "更新预警时间设置信息")]
        [SoapHeader("headerContext", Direction = SoapHeaderDirection.In)]
        [Validation(EnableLog = true)]
        public bool UpdateEarlyWarning(EarlyWarning earlyWarning)
        {
            return EarlyWarningManager.Instance.UpdateEarlyWarning(earlyWarning);
        }

        [WebMethod(Description = "删除预警时间设置信息")]
        [SoapHeader("headerContext", Direction = SoapHeaderDirection.In)]
        [Validation(EnableLog = true)]
        public bool DeleteEarlyWarning(Guid earlyWarningID)
        {
            return EarlyWarningManager.Instance.DeleteEarlyWarning(earlyWarningID);
        }


        /// <summary>
        /// 根据机场四字码获取三字码
        /// </summary>
        /// <param name="code4"></param>
        /// <returns></returns>
        [WebMethod(Description = "根据机场四字码获取三字码")]
        public string GetApt3Code(string code4)
        {
            return InfoAirportHelper.GetApt3Code(code4);
        }

        /// <summary>
        /// 根据机场三字码获取四字码
        /// </summary>
        /// <param name="code3"></param>
        /// <returns></returns>
        [WebMethod(Description = "创建所有预警时间设置信息列表")]
        public string GetApt4Code(string code3)
        {
            return InfoAirportHelper.GetApt4Code(code3);
        }

        /// <summary>
        /// 根据机场三字码或四字码获取机场实体
        /// </summary>
        /// <param name="code3"></param>
        /// <returns></returns>
        [WebMethod(Description = "根据机场三字码或四字码获取机场实体")]
        public InfoAirport GetIntoAirport(string code)
        {
            return InfoAirportHelper.GetIntoAirport(code);
        }

        /// <summary>
        /// 获取所有机场信息列表
        /// </summary>
        /// <returns></returns>
        [WebMethod(CacheDuration = 1200, Description = "获取所有机场信息列表")]
        public List<InfoAirport> GetAllAirports()
        {
            return InfoAirportHelper.GetAllAirports();
        }
    }
}
